package com.woniuxy.util;

import java.util.ArrayList;
import java.util.List;

public class TreeNodeBuilder {
    public static List<TreeNode> build(List<TreeNode> treeNodes, String topPid){
        List<TreeNode> nodes = new ArrayList<>();
        for (TreeNode n1:treeNodes){
            if (topPid.equals(n1.getPid())){
                nodes.add(n1);
            }
            for (TreeNode n2:treeNodes){
                if (n1.getId().equals(n2.getPid())){
                    n1.getChildren().add(n2);
                }
            }
        }
        return nodes;
    }
}
